// pages/classify/classify.js
//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 选项卡配置
    swiper: {
      indicatorDots: false, //是否显示面板指示点
      indicatorColor: "#fff", //指示点颜色
      indicatorActiveColor: "#C69C6D", //当前选中的指示点颜色
      autoplay: false, //是否自动切换
      current: 0, //当前所在滑块的 index
      interval: 5000, //自动切换时间间隔	
      duration: 300, //滑动动画时长
      circular: true, //是否采用衔接滑动
      vertical: false, //滑动方向是否为纵向
      previousMargin: "0px", //前边距，可用于露出前一项的一小部分，接受 px 和 rpx 值
      nextMargin: "0px", //后边距，可用于露出后一项的一小部分，接受 px 和 rpx 值
      displayMultipleItems: 1, //同时显示的滑块数量
      skipHiddenItemLayout: false, //是否跳过未显示的滑块布局，设为 true 可优化复杂情况下的滑动性能，但会丢失隐藏状态滑块的布局信息
      easingFunction: "default", //指定 swiper 切换缓动动画类型
    },
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    navData: [{
        text: '蛋糕',
        dec: "新鲜乳脂奶油蛋糕",
        classifyData: [{
            src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/dangao-1.jpg",
            eTitle: "Deep Bailey's Lovers",
            zTitle: "深爱",
            price: 268.00,
            weight: 454,
            lb: 1.0,
          },
          {
            src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/dangao-1.jpg",
            eTitle: "Deep Bailey's Lovers",
            zTitle: "深爱",
            price: 268.00,
            weight: 454,
            lb: 1.0,
          },
          {
            src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/dangao-1.jpg",
            eTitle: "Deep Bailey's Lovers",
            zTitle: "深爱",
            price: 268.00,
            weight: 454,
            lb: 1.0,
          },
          {
            src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/dangao-1.jpg",
            eTitle: "Deep Bailey's Lovers",
            zTitle: "深爱",
            price: 268.00,
            weight: 454,
            lb: 1.0,
          },
          {
            src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/dangao-1.jpg",
            eTitle: "Deep Bailey's Lovers",
            zTitle: "深爱",
            price: 268.00,
            weight: 454,
            lb: 1.0,
          }
        ]
      },
      {
        text: '冰淇淋',
        dec: "10天生命的意式杰拉朵冰淇淋",
        classifyData: []
      },
      {
        text: '咖啡下午茶',
        dec: "挂耳咖啡",
        classifyData: []
      },
      {
        text: '面包',
        dec: "面包",
        classifyData: []
      },
      {
        text: '常温蛋糕',
        dec: "方便携带，恰到好处的满足",
        classifyData: []
      },
      {
        text: '设计师礼品',
        dec: "设计师礼品专区",
        classifyData: []
      }
    ], //分类数据
    currentTab: 0, // 当前选中项
    navScrollLeft: 0,
    addCartdata: {
      productsArr: [{
          "id": "7681",
          "size": "13.5x13.5",
          "suite_amount": "\u9002\u54083-4\u4eba\u5206\u4eab",
          "booking_hour_limited": "6",
          "cutlery_content": "\u542b5\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
          "price": "268.00",
          "mktprice": "268.00",
          "spec": "1.0\u78c5",
          "pound": "1.00",
          "has_spec_img": 1,
          "img_url": "1.00P-full-13.50.jpg",
          "is_default": "true",
          "has_stock": 10551,
          "cat_id": "49",
          "bn": "201702-10",
          "enName": "Deep Bailey's Lovers",
          "simpleName": "\u6df1\u7231",
          "cakeGoodsId": "387",
          "weight": 454
        },
        {
          "id": "7689",
          "size": "15.5x15.5",
          "suite_amount": "\u9002\u54084-5\u4eba\u5206\u4eab",
          "booking_hour_limited": "6",
          "cutlery_content": "\u542b5\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
          "price": "338.00",
          "mktprice": "338.00",
          "spec": "1.5\u78c5",
          "pound": "1.50",
          "has_spec_img": 1,
          "img_url": "1.00P-full-13.50.jpg",
          "is_default": "false",
          "has_stock": 10132,
          "cat_id": "49",
          "bn": "201702-15",
          "enName": "Deep Bailey's Lovers",
          "simpleName": "\u6df1\u7231",
          "cakeGoodsId": "387",
          "weight": 681
        },
        {
          "id": "7697",
          "size": "17.5x17.5",
          "suite_amount": "\u9002\u54087-8\u4eba\u5206\u4eab",
          "booking_hour_limited": "6",
          "cutlery_content": "\u542b10\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
          "price": "398.00",
          "mktprice": "398.00",
          "spec": "2.0\u78c5",
          "pound": "2.00",
          "has_spec_img": 1,
          "img_url": "1.00P-full-13.50.jpg",
          "is_default": "false",
          "has_stock": 10338,
          "cat_id": "49",
          "bn": "201702-20",
          "enName": "Deep Bailey's Lovers",
          "simpleName": "\u6df1\u7231",
          "cakeGoodsId": "387",
          "weight": 908
        },
        {
          "id": "7705",
          "size": "22.5x22.5",
          "suite_amount": "\u9002\u540811-12\u4eba\u5206\u4eab",
          "booking_hour_limited": "6",
          "cutlery_content": "\u542b15\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
          "price": "598.00",
          "mktprice": "598.00",
          "spec": "3.0\u78c5",
          "pound": "3.00",
          "has_spec_img": 1,
          "img_url": "1.00P-full-13.50.jpg",
          "is_default": "false",
          "has_stock": 10090,
          "cat_id": "49",
          "bn": "201702-30",
          "enName": "Deep Bailey's Lovers",
          "simpleName": "\u6df1\u7231",
          "cakeGoodsId": "387",
          "weight": 1362
        },
        {
          "id": "7713",
          "size": "30x30cm",
          "suite_amount": "\u9002\u540815-20\u4eba\u5206\u4eab",
          "booking_hour_limited": "6",
          "cutlery_content": "\u542b20\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
          "price": "958.00",
          "mktprice": "958.00",
          "spec": "5.0\u78c5",
          "pound": "5.00",
          "has_spec_img": 1,
          "img_url": "1.00P-full-13.50.jpg",
          "is_default": "false",
          "has_stock": 10039,
          "cat_id": "49",
          "bn": "201702-50",
          "enName": "Deep Bailey's Lovers",
          "simpleName": "\u6df1\u7231",
          "cakeGoodsId": "387",
          "weight": 2270
        },
        {
          "id": "",
          "size": "",
          "suite_amount": "",
          "booking_hour_limited": "",
          "cutlery_content": "",
          "price": "",
          "has_spec_img": 1,
          "spec": "\u66f4\u591a",
          "pound": "more",
          "img_url": "1.00P-full-13.50.jpg",
          "is_default": "false",
          "has_stock": true
        }
      ],
      saleTime: {
        "date": "\u4eca\u5929",
        "start_time": "16:00",
        "end_time": "21:30"
      },
      catId: "49",
      isCake: true,
      goodsId: "387",
      isSellOut: false,
      type: "normal"
    }, // 添加到购物车时商品详细信息
    isCloseBombBox: false, //是否关闭模态框
  },
  
  // 监听子组件传递的打开事件
  onOpenBombBox: function() {
    this.setData({
      isCloseBombBox: true
    });
  },

  // 监听子组件传递的关闭事件
  onCloseBombBox: function() {
    this.setData({
      isCloseBombBox: false
    });
  },

  switchNav(event) {
    var cur = event.currentTarget.dataset.current;
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 5;
    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },
  switchTab(event) {
    var cur = event.detail.current;
    var singleNavWidth = this.data.windowWidth / 5;
    this.setData({
      currentTab: cur,
      navScrollLeft: (cur - 2) * singleNavWidth
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          pixelRatio: res.pixelRatio,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      },
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    if (app.globalData.currentTab) {
      this.setData({
        currentTab: app.globalData.currentTab
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
      return {
        title: res.target.dataset.shareinfo.title,
        path: res.target.dataset.shareinfo.path,
        imageUrl: res.target.dataset.shareinfo.imageUrl
      }
    } else {
      return {
        title: '全新品种蛋糕，等你来尝哦！',
        path: 'pages/home/home',
        imageUrl: "http://59.110.237.148/tsy/static_file/applets_21cake/images/banner2.jpg"
      }
    }
  }
})